import { useTranslation } from "react-i18next";
import { BasicTable, useTable, BasicColumn, FormSchema } from "@/components/Table";
import { patientsTransGetlist } from "@/api/MedicalExamination";
import { getAddress } from "@/utils/helper/dataHelper";
import moment from "moment";

export default function clinic_transfer() {
	const { t } = useTranslation();

	const formSchemaTop: FormSchema[] = [
		{
			label: t("felix_ui.cli_name"),
			field: "cliName",
			component: "Input"
		},
		{
			label: t("felix_ui.dept_name"),
			field: "deptName",
			component: "Select",
			componentProps: {
				options: [
					{ label: "1", value: "1" },
					{ label: "2", value: "2" }
				]
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.sq_numb"),
			dataIndex: "sqNumb",
			render: (text, record, index) => +index + 1
		},
		{
			title: t("felix_ui.patient_ID"),
			dataIndex: "patientId"
		},
		{
			title: t("felix_ui.full_name"),
			dataIndex: "fullName",
			render: (_, record: any) => (record?.patients ? record?.patients?.fullName : "")
		},
		{
			title: t("felix_ui.birthday"),
			dataIndex: "birthday",
			render: (_, record: any) => (record?.patients ? moment(record.patients.birthday).year() : "")
		},
		{
			title: t("felix_ui.cli_name"),
			dataIndex: "clinicName"
		},
		{
			title: t("felix_ui.clinic_transto"),
			dataIndex: "transTo"
		},
		{
			title: t("felix_ui.exam_form"),
			dataIndex: "exam_form"
		},
		{
			title: t("felix_ui.address"),
			dataIndex: "address",
			render: (_, record: any) => getAddress(record?.patients)
		},
		{
			title: t("felix_ui.trans_from"),
			dataIndex: "transFrom"
		},
		{
			title: t("felix_ui.doctor"),
			dataIndex: "referralDoctor"
		}
	];

	const [registerTable] = useTable({
		api: patientsTransGetlist,
		columns,
		formConfig: {
			labelWidth: 120,
			schemas: formSchemaTop,
			showActionButtonGroup: true,
			showAdvancedButton: false
		},
		useSearchForm: true
	});

	/** Function */

	return (
		<div className="page block">
			<BasicTable register={registerTable}></BasicTable>
		</div>
	);
}
